package com.example.controller.before;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.entity.UserAuth;
import com.example.service.UserAuthService;
import com.example.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "小程序贫困用户申请") //swagger的注释
@CrossOrigin
@RequestMapping("/userAuthBefore")
@RestController
public class UserAuthBeforeController {

    @Autowired
    private UserAuthService userAuthService;

    @ApiOperation(value = "查询用户申请信息")
    @GetMapping("selectUserAuth/{userId}")
    public R selectUserAuth(@PathVariable String userId) {
        QueryWrapper<UserAuth> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id", userId);
        wrapper.eq("is_poor", 0);

        UserAuth userAuth = userAuthService.getOne(wrapper);
        return R.ok().data("auth", userAuth);
    }


    @ApiOperation(value = "用户贫困申请")
    @PostMapping("addUserAuth")
    public R addUserAuth(@RequestBody UserAuth userAuth) {
        boolean b = userAuthService.save(userAuth);
        if (b) {
            return R.ok();
        } else {
            return R.error().message("提交失败！");
        }
    }

}
